<template>
  <u-popup
    :show="fenShow"
    mode="bottom"
    @touchmove.stop.prevent="moveHandle"
    @close="close"
    :round="10"
    :closeable="false"
    bgColor="#F5F6F8"
  >
    <view class="content_c">
      <view class="fen_box_title">分享至</view>
      <view class="fen_box" v-if="showLh">
        <view class="fen_box_cen">
          <button open-type="share" class="fen_box_cen_l" @click="toppicWxShare">
            <image
              src="https://ossresource.miyingbl.com/uploads/20240307/1b8d3a17f569740d545b17facde7d718.png"
              class="fen_box_cen_l_img"
            ></image>
            <view class="fen_box_cen_l_te">微信好友</view>
          </button>
          <button open-type="share" class="fen_box_cen_l" @click="toppicPyShare">
            <image
              src="https://ossresource.miyingbl.com/uploads/20240307/9c488feb2f34a1588dd945dbcf5fec32.png"
              class="fen_box_cen_l_img"
            ></image>
            <view class="fen_box_cen_l_te">朋友圈</view>
          </button>
        </view>
      </view>
      <view v-else>
        <view class="fen_box2">
          <view class="fen_box_cen">
            <button open-type="share" class="fen_box_cen_l" @click="toppicWxShare">
              <image
                src="https://ossresource.miyingbl.com/uploads/20240307/1b8d3a17f569740d545b17facde7d718.png"
                class="fen_box_cen_l_img"
              ></image>
              <view class="fen_box_cen_l_te">微信好友</view>
            </button>
            <button
              v-if="isDoctor"
              open-type="share"
              class="fen_box_cen_l"
              @click="gotoChat(doctorInfo)"
            >
              <image :src="doctorInfo?.avatar" class="fen_box_cen_l_img"></image>
              <view class="fen_box_cen_l_te">{{ doctorInfo?.dname }}</view>
            </button>
            <button v-else open-type="share" class="fen_box_cen_l" @click="toppicPyShare">
              <image
                src="https://ossresource.miyingbl.com/uploads/20240307/9c488feb2f34a1588dd945dbcf5fec32.png"
                class="fen_box_cen_l_img"
              ></image>
              <view class="fen_box_cen_l_te">朋友圈</view>
            </button>
          </view>
        </view>
      </view>
      <view v-if="info?.user_id != userInfo?.uid && token && showLh"><u-line></u-line></view>
      <!-- <view><u-line></u-line></view> -->
      <view class="fen_box" v-if="info?.user_id != userInfo?.uid && token && showLh">
        <!-- <view class="fen_box"> -->
        <view class="fen_box_cen">
          <view class="fen_box_cen_l" @click="lahei()" v-show="info?.user_id != userInfo?.uid">
            <image
              src="https://ossresource.miyingbl.com/uploads/20240304/47f1b605729e5f10ac2f5bdf6a6d8817.png"
              class="fen_box_cen_l_img"
            ></image>
            <view class="fen_box_cen_l_te">不喜欢</view>
          </view>
          <view class="fen_box_cen_l" @click="toReport" v-show="info?.user_id != userInfo?.uid">
            <image
              src="https://ossresource.miyingbl.com/uploads/20240304/5b14bb94eae78c1a45d0d58b8fecc0d5.png"
              class="fen_box_cen_l_img"
            ></image>
            <view class="fen_box_cen_l_te">举报</view>
          </view>
        </view>
      </view>
      <view class="cencelBtn" @click="close()"> 取消 </view>
    </view>
  </u-popup>
  <!-- 拉黑 -->
  <u-popup
    :show="laheiShow"
    mode="bottom"
    @close="closeLafei"
    :round="10"
    :closeable="false"
    bgColor="#F5F6F8"
  >
    <view>
      <view class="fen_box">
        <view class="fen_box_cen">
          <view class="lh_box_cen_l" @click="negativeFeedback(1)">
            <image
              src="https://ossresource.miyingbl.com/uploads/20240307/f6b32f7b63ee1ecc427102897e0cde2c.png"
              class="fen_box_cen_l_img"
            ></image>
            <view class="fen_box_cen_l_te">不感兴趣</view>
          </view>
          <view class="lh_box_cen_l" @click="negativeFeedback(2)">
            <image
              src="https://ossresource.miyingbl.com/uploads/20240307/5210aee89f7a4118171e4be748182b1f.png"
              class="fen_box_cen_l_img"
            ></image>
            <view class="fen_box_cen_l_te">不喜欢作者</view>
          </view>
        </view>
      </view>

      <view class="cencelBtn" @click="closeLafei()"> 取消 </view>
    </view>
  </u-popup>
</template>

<script setup>
import { ref, nextTick } from 'vue'
import { showToast, navigateTo, showLoading, hideLoading, showModal } from '@/utils'
import { useMemberStore, useSystemStore } from '@/stores'
import { negativeFeedbackApi, blockUserApi } from '@/api/home'
import { termBabyFull, getDoctorInfo } from '@/api/pregnancy/index'
import { onShow, onLoad } from '@dcloudio/uni-app'
import {notInterestedApi} from '@/api/social'
const popup = ref(null)
const userInfo = ref({})
const token = ref()
const emit = defineEmits(['toLogin', 'gotoChat'])
const fenShow = ref(false)
const laheiShow = ref(false)
//医生信息
const doctorInfo = ref({})
// 是否显示拉黑  不传默认显示
const isShowFB = ref(true)
// showLh 是否显示拉黑
const props = defineProps({
  showLh: {
    type: Boolean,
    default: true,
  },
  otherType: {
    type: Boolean,
    default: false,
  },
  isDoctor: {
    type: Boolean,
    default: false,
  },
})

const info = ref({
  // 传路径 + 参数  不传默认首页
  // pages/index/index?id=....
  path: 'pages/index/index',
  // 分享图片 + 参数  不传默认logo图
  imageUrl:
    'https://ossresource.miyingbl.com/uploads/20240407/01ee3354aaba5358383f38331eec8fec.png',
  // 分享标题 + 参数  不传默认‘咪婴伴侣’
  title: '咪婴伴侣',
  // 分享简介 + 参数  不传默认‘咪婴伴侣’
  summary: '咪婴伴侣',
})
defineExpose({
  open,
})
onLoad(() => {
  if (props.isDoctor) {
    termBabyFn()
  }
})
onShow(() => {
  const store = useMemberStore()
  userInfo.value = store.userInfo
  token.value = store?.token
})
function close() {
  laheiShow.value = false
  fenShow.value = false
}
//获取医生信息
async function termBabyFn() {
  const res = await termBabyFull()
  if (res.code == 200) {
    getDoctor(res.data.data[0].doctor_id)
  }
}
async function getDoctor(doctorId) {
  const res = await getDoctorInfo({ doctor_id: doctorId })
  if (res?.code == 200) {
    doctorInfo.value = res.data.detail
  }
}
function gotoChat(i) {
  fenShow.value = false
  console.log(i)
  emit('gotoChat', i)
}
//
const path = ref('pages/index/index')
const isway = ref(false)
function open(row) {
  if (row?.content_type == 'kp') {
    isway.value = true
  } else {
    isway.value = false
  }
  console.log(row, isway.value)
  //获取当前页面栈的实例
  let pages = getCurrentPages()
  //获取当前页面
  let currentPage = pages[pages.length - 1]
  let url = currentPage.route
  //如果当前处于首页，则...
  info.value = row
  if (row?.path) {
    path.value = row.path
  } else {
    path.value = url
  }
  if (row?.imageUrl) {
    imageUrl.value = row.imageUrl
  }

  fenShow.value = true
}
const imageUrl = ref(
  'https://ossresource.miyingbl.com/uploads/20240407/01ee3354aaba5358383f38331eec8fec.png',
)
function moveHandle() {
  return false
}
// 分享
function toppicWxShare() {
  console.log(path.value)
  /* #ifdef H5 */
  uni.showToast({
    icon: 'error',
    title: '暂不支持分享',
  })

  fenShow.value = false
  /* #endif */
  /* #ifdef APP-PLUS */
  uni.share({
    provider: 'weixin',
    type: 0,
    scene: 'WXSceneSession',
    href: isway.value
      ? `https://weapp.miyingbl.com/download/index.html?id=${info?.value?.id}&path=baby/science/index`
      : `https://a.app.qq.com/o/simple.jsp?pkgname=com.miyingbl.mybl&android_schema=mybl://${path.value}&ios_schema=mybl://${path.value}`,
    title: info.value?.title || '咪婴伴侣',
    summary: info.value?.summary || '咪婴伴侣',
    imageUrl: info.value?.imageUrl || imageUrl.value,
    success: function (res) {
      uni.showToast({
        title: '分享成功',
        icon: 'success',
      })
      uni.hideLoading()
      fenShow.value = false
    },
    fail: function (err) {
      console.log('分享失败', err)
      uni.showToast({
        title: '分享失败',
        icon: 'none',
        duration: 2000,
      })
      uni.hideLoading()
      fenShow.value = false
    },
  })
  /* #endif */
}
// 分享到朋友圈
function toppicPyShare() {
  /* #ifdef H5 */
  uni.showToast({
    icon: 'error',
    title: '暂不支持分享',
  })
  fenShow.value = false
  /* #endif */
  /* #ifdef APP-PLUS */
  uni.share({
    provider: 'weixin',
    type: 0,
    scene: 'WXSceneTimeline',
    href: isway.value
      ? `https://weapp.miyingbl.com/download/index.html?id=${info?.value?.id}&path=baby/science/index`
      : `https://a.app.qq.com/o/simple.jsp?pkgname=com.miyingbl.mybl&android_schema=mybl://${path.value}&ios_schema=mybl://${path.value}`,
    title: info.value?.title || '咪婴伴侣',
    summary: info.value?.summary || '咪婴伴侣',
    imageUrl: info.value?.imageUrl || imageUrl.value,
    success: function (res) {
      uni.showToast({
        title: '分享成功',
        icon: 'success',
      })
      uni.hideLoading()
      fenShow.value = false
    },
    fail: function (err) {
      console.log('分享失败', err)
      uni.showToast({
        title: '分享失败',
        icon: 'none',
        duration: 2000,
      })
      uni.hideLoading()
      fenShow.value = false
    },
  })
  /* #endif */
}
function toReport() {
  fenShow.value = false
  let type = info.value.content_type == 'dt' ? 1 : 2
  uni.navigateTo({
    url: `/socials/report/report?id=${info.value.id}&type=${props.otherType ? 8 : type}`,
  })
}

const closeLafei = () => {
  laheiShow.value = false
}
const lahei = () => {
  fenShow.value = false
  laheiShow.value = true
}

const negativeFeedback = (tab) => {
  notInterestedApi({
    id: info.value.id,
    tab:tab,
    type: info.value.content_type == 'dt' ? 1 : 2,
  }).then((res) => {
    uni.showToast({
      title: res.message,
      icon: 'none',
    })
    laheiShow.value = false
  })
}

// 拉黑作者
function defriend() {
  laheiShow.value = false
  uni.showModal({
    title: '温馨提示',
    content: '您确定要拉黑该用户吗？',
    showCancel: true,
    success: function (res) {
      if (res.confirm) {
        blockUserApi({ to_uid: info.value.uid }).then((result) => {
          uni.setStorageSync('dle', info.value.id)
          negativeFeedback()
          uni.showToast({
            title: result.msg,
            icon: 'success',
            duration: 1500,
            success: () => {},
          })
        })
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    },
  })
}
</script>

<style lang="scss" scoped>
::v-deep .vue-ref {
  padding-bottom: 0 !important;
}

.content_c {
  width: 100%;
  border-radius: 16rpx 16rpx 0 0;
  background-color: #f5f6f8;
  // padding-bottom: 60rpx;

  .fen_box_title {
    text-align: center;
    font-size: 32rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: 500;
    color: #333333;
    line-height: 90rpx;
    height: 90rpx;
  }

  .fen_box {
    width: 100%;
    border-radius: 10rpx 10rpx 0 0;
    padding: 0 24rpx 24rpx;

    .fen_box_cen {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-start;
      padding-top: 20rpx;

      .fen_box_cen_l {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        width: 150rpx;
        margin: 0;
        line-height: 1;
        background-color: transparent;

        .fen_box_cen_l_img {
          width: 100rpx !important;
          height: 100rpx !important;
          border-radius: 50%;
        }

        .fen_box_cen_l_te {
          font-size: 28rpx;
          font-family: PingFang SC, PingFang SC;
          font-weight: 500;
          color: #333333;
          line-height: 80rpx;
        }
      }
    }
  }
}
.fen_box_cen {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  padding-top: 20rpx;
}
.lh_box_cen_l {
  width: 216rpx;
  padding: 10rpx 0 15rpx;
  background: #ffffff;
  border-radius: 14rpx 14rpx 14rpx 14rpx;
  text-align: center;
  margin: 10rpx 20rpx 30rpx;
  font-weight: 500;
  font-size: 24rpx;
  color: #333333;
  image {
    width: 75rpx;
    height: 75rpx;
    display: block;
    margin: 0 auto;
  }
}
.fen_box2 {
  margin: 0 146rpx;
  border-radius: 10rpx 10rpx 0 0;
  padding: 0 24rpx 24rpx;

  .fen_box_cen {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding-top: 20rpx;

    .fen_box_cen_l {
      text-align: center;
      width: 150rpx;
      margin: 0;
      line-height: 1;

      .fen_box_cen_l_img {
        width: 100rpx !important;
        height: 100rpx !important;
        border-radius: 50%;
      }

      .fen_box_cen_l_te {
        margin-top: 20rpx;
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 28rpx;
        color: #333333;
        line-height: 33rpx;
      }
    }

    .lh_box_cen_l {
      width: 216rpx;
      padding: 10rpx 0 15rpx;
      background: #ffffff;
      border-radius: 14rpx 14rpx 14rpx 14rpx;
      text-align: center;
      margin: 10rpx 20rpx;
      font-weight: 500;
      font-size: 24rpx;
      color: #333333;

      image {
        width: 75rpx;
        height: 75rpx;
        display: block;
        margin: 0 auto;
      }
    }
  }
}
.cencelBtn {
  width: 702rpx;
  height: 88rpx;
  line-height: 88rpx;
  text-align: center;
  background: #ffffff;
  border-radius: 16rpx;
  font-weight: 400;
  font-size: 30rpx;
  color: #aaaaaa;
  margin: 0 auto 20rpx;
}
</style>
